import { track, trigger } from "./effect.js";
import { TrackOpTypes,TriggerOpTypes } from "./operations.js";
import { hasChanged } from "./utils.js";

export function ref(value) {
    return {
        get value() {
            track(this,TrackOpTypes.Get, 'value');
            return value;
        },
        set value(newValue) {
            if (!hasChanged(newValue, value)) return;
            value = newValue;
            trigger(this,TriggerOpTypes.Set, 'value');
        }
    }
}